class NewsletterController < ApplicationController
  def send_monthly_newsletter
    books = Book.find(:all)
    Newsletter.deliver_monthly_newsletter(books )
    flash[:notice] = "Monthly newsletter has been sent"
    redirect_to :controller => "books", :action => "index"
    
  rescue Exception => e
    logger.error "A technical problem prevented monthly newsletter to be sent : #{e.message}"
    flash[:notice] = "A technical problem prevented monthly newsletter to be sent : #{e.message}"
    redirect_to :controller => "books", :action => "index"
    # raise e
  end
  
  def send_free_ebook
    book = Book.find(params[:id])
    Newsletter.deliver_free_ebook(book)
    flash[:notice] = "Free ebook has been sent"
    redirect_to :controller => "books", :action => book.id
    
  rescue Exception => e
    logger.error "A technical problem prevented free ebook to be sent : #{e.message}"
    flash[:notice] = "A technical problem prevented free ebook to be sent : #{e.message}"
    redirect_to :controller => "books", :action => book.id
  end
end